Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split public and private i18n APIs #6022

Merged

Conversation

Jackenmen
Copy link
Member

@Jackenmen Jackenmen commented Apr 15, 2023

Description of the changes

  • Move private i18n APIs to redbot.core._i18n and name them more sensibly (set_locale, set_regional_format, and reload_locales which I've moved to redbot.core._i18n and renamed to set_global_locale, set_global_regional_format, and _reload_locales)
  • Prefix get_locale_path() with _
  • Publicize and document set_contextual_locale() and set_contextual_regional_format()
    • changed set_contextual_locale() and set_contextual_regional_format() to verify input
  • Altered the ContextVar logic to not keep a default value and instead pass the default value to context_var.get() call

Have the changes in this PR been tested?

Yes

@Jackenmen Jackenmen added Type: Enhancement Something meant to enhance existing Red features. Breaking Change Will potentially break some cogs. labels Apr 15, 2023
@github-actions github-actions bot added Category: Core - i18n This is related to the i18n core API or locale files. Category: Core - Bot Class This is related to the `redbot.core.bot.Red` class. Category: Core - Bot Commands This is related to core commands (Core and CogManagerUI cog classes). Category: Meta This is related to the repository maintenance. labels Apr 15, 2023
@Jackenmen Jackenmen force-pushed the i18n_api_changes_for_rarely_used branch from a532707 to 97cb7bc Compare April 15, 2023 20:15
@Jackenmen Jackenmen added this to the 3.5.1 milestone Apr 15, 2023
@Jackenmen Jackenmen force-pushed the i18n_api_changes_for_rarely_used branch from 97cb7bc to 0d2e131 Compare May 8, 2023 09:33
@Jackenmen Jackenmen changed the title Document and clarify publicity of rarely used i18n APIs Split public and private i18n APIs May 8, 2023
@Jackenmen Jackenmen removed the Breaking Change Will potentially break some cogs. label May 8, 2023
@Jackenmen Jackenmen modified the milestones: 3.5.3, 3.5.2, 3.6.0 May 11, 2023
@Jackenmen Jackenmen modified the milestones: 3.5.6, 3.5.7 Mar 18, 2024
@Jackenmen Jackenmen modified the milestones: 3.5.9, 3.5.10 Apr 20, 2024
@Jackenmen Jackenmen modified the milestones: 3.5.14, 3.5.x Dec 24, 2024
@Flame442 Flame442 self-assigned this Jan 27, 2025
@Flame442 Flame442 modified the milestones: 3.5.x, 3.5.15 Jan 27, 2025
Copy link
Member

@Flame442 Flame442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bop

@Flame442 Flame442 merged commit a0c1713 into Cog-Creators:V3/develop Jan 27, 2025
17 checks passed
@red-githubbot red-githubbot bot added the Changelog Entry: Pending Changelog entry for this PR hasn't been added by repo maintainers yet. label Jan 27, 2025
@Jackenmen Jackenmen deleted the i18n_api_changes_for_rarely_used branch January 27, 2025 00:33
@Jackenmen Jackenmen modified the milestones: 3.5.16, 3.5.15 Feb 3, 2025
@Jackenmen Jackenmen added Changelog Entry: Added Changelog entry for this PR has already been added to changelog PR. and removed Changelog Entry: Pending Changelog entry for this PR hasn't been added by repo maintainers yet. labels Feb 3, 2025
@Skyridr
Copy link

Skyridr commented Feb 5, 2025

Is there any specific reason why this breaks the entire bot running inside an incus container? Even if local is set to en_US (was C previously), the bot won't start up.

[2025-02-05 08:20:52] [DEBUG] red.main: ====Basic Config====
[2025-02-05 08:20:52] [DEBUG] red.main: Data Path: /home/eve/eve
[2025-02-05 08:20:52] [DEBUG] red.main: Storage Type: JSON
[2025-02-05 08:20:52] [CRITICAL] red.main: The main bot task didn't handle an exception and has crashed
Traceback (most recent call last):
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 40, in _get_standardized_locale_name
locale = Locale.parse(language_code, sep="-")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/eve/redenv/lib/python3.11/site-packages/babel/core.py", line 349, in parse
raise ValueError(msg) # parse_locale would raise a ValueError, so let's do that here
^^^^^^^^^^^^^^^^^^^^^
ValueError: ("Empty locale identifier value: ''\n\nIf you didn't explicitly pass an empty value to a Babel function, this could be caused by there being no suitable locale environment variables for the API you tried to use.",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/main.py", line 470, in red_exception_handler
red_task.result()
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/main.py", line 369, in run_bot
await red.start(token)
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 1278, in start
await self._pre_login()
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 1150, in _pre_login
_i18n.set_global_regional_format(i18n_regional_format)
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 60, in set_global_regional_format
language_code = _get_standardized_locale_name(language_code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 42, in _get_standardized_locale_name
raise ValueError("Invalid language code. Use format: en-US")
ValueError: Invalid language code. Use format: en-US
[2025-02-05 08:20:52] [WARNING] red.main: Attempting to die as gracefully as possible...
[2025-02-05 08:20:52] [INFO] red.main: Shutting down from unhandled exception
[2025-02-05 08:20:52] [ERROR] asyncio: Task exception was never retrieved
future: <Task finished name='Task-2' coro=<shutdown_handler() done, defined at /home/eve/redenv/lib/python3.11/site-packages/redbot/main.py:425> exception=AttributeError("'Red' object has no attribute '_AutoShardedClient__queue'")>
Traceback (most recent call last):
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/main.py", line 441, in shutdown_handler
await red.close()
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 2259, in close
await super().close()
File "/home/eve/redenv/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 247, in close
await super().close() # type: ignore
^^^^^^^^^^^^^^^^^^^^^
File "/home/eve/redenv/lib/python3.11/site-packages/discord/shard.py", line 498, in close
await self._closing_task
File "/home/eve/redenv/lib/python3.11/site-packages/discord/shard.py", line 495, in _close
self.__queue.put_nowait(EventItem(EventType.clean_close, None, None))
^^^^^^^^^^^^
AttributeError: 'Red' object has no attribute '_AutoShardedClient__queue'

@Jackenmen
Copy link
Member Author

See #6517. Our guess is that invalid configuration (which this is caused by) could have been introduced by some version of 3rd-party dashboard cog. We've only seen a single report of this other than yours so we haven't rushed a hot fix release.

@Skyridr
Copy link

Skyridr commented Feb 5, 2025

See #6517. Our guess is that invalid configuration (which this is caused by) could have been introduced by some version of 3rd-party dashboard cog. We've only seen a single report of this other than yours so we haven't rushed a hot fix release.

Ty, that fixed it! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Core - Bot Class This is related to the `redbot.core.bot.Red` class. Category: Core - Bot Commands This is related to core commands (Core and CogManagerUI cog classes). Category: Core - i18n This is related to the i18n core API or locale files. Category: Meta This is related to the repository maintenance. Changelog Entry: Added Changelog entry for this PR has already been added to changelog PR. Type: Enhancement Something meant to enhance existing Red features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants